package cloud.hadoop.bds.controller;

import cloud.hadoop.bds.model.common.Result;
import cloud.hadoop.bds.pojo.PageUtil;
import cloud.hadoop.bds.pojo.User;
import cloud.hadoop.bds.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    private final UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    /**
     * 验证用户是否存在数据库中
     */
    @PostMapping("/login")
    public Result checkUser(@RequestBody User user) {
        return userService.checkUser(user);
    }

    /**
     * 注册用户
     */
    @PostMapping("/register")
    public Result registerUser(@RequestBody User user) {
        return userService.registerUser(user);
    }

    /**
     * 获取用户列表
     */
    @PostMapping("/userList")
    public Result getUserList(@RequestBody PageUtil page) {
        return userService.selectUser(page.getPageNum(), page.getPageSize());
    }

    /**
     * 模糊查询用户列表
     */
    @PostMapping("/likeUserList/{account}")
    public Result likeUserList(@PathVariable String account) {
        return userService.selectLikeUser(account);
    }

    /**
     * 删除用户信息
     */
    @PostMapping("/deleteUser/{id}")
    public Result deleteUser(@PathVariable Integer id) {
        return userService.deleteUser(id);
    }

    /**
     * 更改用户信息
     */
    @PostMapping("/update")
    public Result updateUser(@RequestBody User user) {
        return userService.updateUser(user);
    }
}
